﻿using System.Net.Sockets;
using Letter.Net.Sockets;

namespace Letter.Net.Session;

public static class SessionProvider
{
    public static ISession CreateTcpSessionFromSenderSole(Socket socket, in TransportSettings settings, AConnection connection)
    {
        var operators = new TcpSocketOperators<TcpSnderSole>();
        operators.rcver = new TcpRcver(settings.scheduler);
        operators.snders = new TcpSnderSole(settings.scheduler);
        
        return new TcpSession<TcpSnderSole>(socket, settings, operators, connection);
    }
    
    public static ISession CreateTcpSessionFromSenderPool(Socket socket, in TransportSettings settings, AConnection connection)
    {
        var operators = new TcpSocketOperators<TcpSnderPool>();
        operators.rcver = new TcpRcver(settings.scheduler);
        operators.snders = new TcpSnderPool(settings.scheduler);
        
        return new TcpSession<TcpSnderPool>(socket, settings, operators, connection);
    }

    public static ISession CreateUdpSessionFromSenderSole(Socket socket, in TransportSettings settings, AConnection connection)
    {
        var operators = new UdpSocketOperators<UdpSnderSole>();
        operators.rcver = new UdpRcver(settings.scheduler);
        operators.snders = new UdpSnderSole(settings.scheduler);

        return new UdpSession<UdpSnderSole>(socket, settings, operators, connection);
    }
    
    public static ISession CreateUdpSessionFromSenderPool(Socket socket, in TransportSettings settings, AConnection connection)
    {
        var operators = new UdpSocketOperators<UdpSnderPool>();
        operators.rcver = new UdpRcver(settings.scheduler);
        operators.snders = new UdpSnderPool(settings.scheduler);

        return new UdpSession<UdpSnderPool>(socket, settings, operators, connection);
    }
}
